package com.yanqu.road.server.logic.activity.condition.musicroom;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.musicroom.UserMusicRoomBuildingData;
import com.yanqu.road.entity.task.TaskConditionInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.musicroom.MusicRoomModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.task.BaseCondition;
import com.yanqu.road.server.logic.task.BaseTaskData;

import java.math.BigInteger;

public class MusicRoomBuildingUnlockCondition extends BaseCondition {

    public MusicRoomBuildingUnlockCondition(TaskConditionInfo taskConditionInfo, BaseTaskData baseTaskData, BigInteger value, Object initArgs) {
        super(taskConditionInfo, baseTaskData, value, initArgs);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.MusicRoomBuildingUnlock.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.MusicRoomBuildingUnlock.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        BigInteger param4 = taskConditionInfo.getParamList().get(3);
        return getValue().compareTo(param4) >= 0;
    }

    @Override
    protected void changeValue(Object object) {
//        int checkBuildId = taskConditionInfo.getParamList().get(3).intValue();
//        UserMusicRoomBuildingData buildingData = player.getModule(MusicRoomModule.class).getBuildingDataMap().get(checkBuildId);
//        if (buildingData != null) {
//            setValue(BigInteger.valueOf(checkBuildId));
//        }
        initValue();
    }

    @Override
    public void initValue() {
        int checkBuildId = taskConditionInfo.getParamList().get(3).intValue();
        UserMusicRoomBuildingData buildingData = player.getModule(MusicRoomModule.class).getBuildingDataMap().get(checkBuildId);
        if (buildingData != null) {
            setValue(BigInteger.valueOf(checkBuildId));
        } else {
            setValue(BigInteger.ZERO);
        }
    }
}
